/**
 * 
 */
package com.wubo.sec.event;

import org.springframework.context.ApplicationEvent;

/**
 * @author WuBo
 * @CreateDate 2010-12-29
 * @version 1.0.1
 */
public class EntityEvent<E>  extends ApplicationEvent {
	/**
	 * 
	 */
	private static final long serialVersionUID = -8230802983293128421L;
	
	public static final Type ADD = Type.ADD;
	public static final Type UPDATE = Type.UPDATE;
	public static final Type DELETE = Type.DELETE;
	
	protected final Type type;
	
	private E oldEntity;
	
	public EntityEvent(E entity, Type type){
		super(entity);
		this.type = type;
	}
	
	public EntityEvent(E oldEntity, E newEntity, Type type){
		super(newEntity);
		this.oldEntity = oldEntity;
		this.type = type;
	}
	
	public Type getType(){
		return type;
	}
	
	@SuppressWarnings("unchecked")
	public E getEntity(){
		return (E) super.source;
	}
	
	public E getOldEntity(){
		return this.oldEntity;
	}
	
	public static enum Type {
		ADD{},
		UPDATE{},
		DELETE{};
	}
}
